package com.jarvis.pzz.modules.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jarvis.pzz.R;
import com.jarvis.pzz.models.FeedBackModel;
import com.jarvis.pzz.models.VCModel;
import com.jarvis.pzz.modules.findshop.model.FindFacilitiesModel;
import com.jarvis.pzz.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class FeedBackListAdapter extends BaseAdapter {
    private List<FeedBackModel> list;
    private Context context;

    public FeedBackListAdapter(List<FeedBackModel> list, Context context) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final FeedBackModel feedBackModel = list.get(position);
        final String isdisplay = feedBackModel.getIsdisplay();
        convertView = LayoutInflater.from(context).inflate(R.layout.item_feed_back, null);
        TextView tv_name = ViewHolderUtil.get(convertView, R.id.tv_name);
        TextView tv_value = ViewHolderUtil.get(convertView, R.id.tv_value);
        final RelativeLayout rel_value = ViewHolderUtil.get(convertView, R.id.rel_value);
        RelativeLayout rel_title = ViewHolderUtil.get(convertView, R.id.rel_title);
        final ImageView img_more = ViewHolderUtil.get(convertView, R.id.img_more);

        tv_name.setText(feedBackModel.getTitle());
        tv_value.setText(feedBackModel.getContent());
        if("1".equals(isdisplay)){
            rel_value.setVisibility(View.GONE);
            img_more.setBackgroundResource(R.drawable.img_down);
        }else {
            rel_value.setVisibility(View.VISIBLE);
            img_more.setBackgroundResource(R.drawable.img_up);

        }
        rel_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if("1".equals(isdisplay)){
                    rel_value.setVisibility(View.VISIBLE);
                    img_more.setImageResource(R.drawable.img_up);
                    list.get(position).setIsdisplay("0");
                    notifyDataSetChanged();
                }else {
                    rel_value.setVisibility(View.GONE);
                    img_more.setImageResource(R.drawable.img_down);
                    list.get(position).setIsdisplay("1");
                    notifyDataSetChanged();
                }
            }
        });
        return convertView;
    }
}
